/**
 * @author Matan Mizrahi,Chen weissman
 * Introduction to computer science, assingment5
 * Date:2.1.2011
 */
public abstract class CompoundExpression implements Expression  {
//***********************************Fields*******************************//
private Expression[] exArr;
//*****************************Constructors*******************************//
	public CompoundExpression(Expression[] exArr){
		if (exArr==null)
			throw new NullPointerException("The constructor got a null argument.");
		else
		this.exArr=exArr;
	}
//**********************************Methods*******************************//
		/**
		 * 
		 * Evaluates the expression given an assignment. 
		 * @param assign the given assignment.
		 * @return The value of this expression with respect
		 * to the given assignment. Any variable in the expression 
		 * which is not assigned with a value under the assignment
		 * {@code assign} will be considered as a variable which
		 * value is 0.
		 * @throws Exception  in case the assignment is null or if the variable is not assigned to a value
		 */
		public abstract double evaluate(Assignment assign) throws Exception;
		
		/**
		 * 
		 * Derivative operation on Expression according to varName.
		 * @param varName the name of the variable according to which
		 * the expression is derived.
		 * @return New expression representing the derivative of this expression.
		 */
		public abstract Expression derivative(char varName);
		
		/**
		 * Replicating the invoking object.
		 * 
		 * @return a replicate of this object. The returned object has
		 * to be a new object (with a different address than this
		 * object), but equivalent to the this object under the 
		 * application of the {@code equals(Object other)} method.
		 */
		@SuppressWarnings("null")
		public  Expression replicate(){ 
		CompoundExpression ans=null;
		for (int i=0;i<exArr.length;i++)
			ans.exArr[i]=exArr[i];
		return ans;
		}
	}

